Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / core / model / src / commonTest / kotlin / org / meshtastic / core / model / util / CodePointUtilsTest.kt

Displaying Raw • Download

core/model/src/commonTest/kotlin/org/meshtastic/core/model/util/CodePointUtilsTest.kt 01cd54907d62cd90913d3d071b6bc240cae365ef (01cd5490) Text, 3.60 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.model.util

Tff7b72import T7ee787kotlin.test.Test
Tff7b72import T7ee787kotlin.test.assertEquals
Tff7b72import T7ee787kotlin.test.assertFalse
Tff7b72import T7ee787kotlin.test.assertTrue

Tff7b72class T56d364CodePointUtilsTest Tb4b4b4{

Tf0883e@Test
Tff7b72fun Td2a8ff`isValidCodePoint accepts scalar values`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3assertTrueTb4b4b4(Ta5d6ff'A'Tb4b4b4.Te6edf3codeTb4b4b4.Te6edf3isValidCodePointTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertTrueTb4b4b4(Te6edf3PUSHPIN_CODE_POINTTb4b4b4.Te6edf3isValidCodePointTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertTrueTb4b4b4(T79c0ff0.Te6edf3isValidCodePointTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertTrueTb4b4b4(T79c0ff0Te6edf3x10FFFFTb4b4b4.Te6edf3isValidCodePointTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`isValidCodePoint rejects out of range and surrogates`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3assertFalseTb4b4b4(Tb4b4b4(Tff7b72-T79c0ff1Tb4b4b4)Tb4b4b4.Te6edf3isValidCodePointTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertFalseTb4b4b4(T79c0ff0Te6edf3x110000Tb4b4b4.Te6edf3isValidCodePointTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertFalseTb4b4b4(Tffa657IntTb4b4b4.Te6edf3MAX_VALUETb4b4b4.Te6edf3isValidCodePointTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertFalseTb4b4b4(Tffa657IntTb4b4b4.Te6edf3MIN_VALUETb4b4b4.Te6edf3isValidCodePointTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertFalseTb4b4b4(T79c0ff0Te6edf3xD800Tb4b4b4.Te6edf3isValidCodePointTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertFalseTb4b4b4(T79c0ff0Te6edf3xDFFFTb4b4b4.Te6edf3isValidCodePointTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`toCodePointString encodes bmp and supplementary planes`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3assertEqualsTb4b4b4(Ta5d6ff"Ta5d6ffATa5d6ff"Tb4b4b4, Ta5d6ff'A'Tb4b4b4.Te6edf3codeTb4b4b4.Te6edf3toCodePointStringTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertEqualsTb4b4b4(Ta5d6ff"Ta5d6ff📍Ta5d6ff"Tb4b4b4, Te6edf3PUSHPIN_CODE_POINTTb4b4b4.Te6edf3toCodePointStringTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertEqualsTb4b4b4(Ta5d6ff"Ta5d6ff􏿿Ta5d6ff"Tb4b4b4, T79c0ff0Te6edf3x10FFFFTb4b4b4.Te6edf3toCodePointStringTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`toCodePointString falls back instead of throwing on out-of-range input`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// Values that reach Waypoint.icon from the wire; each of these throws from Character.toChars.
Te6edf3assertEqualsTb4b4b4(Ta5d6ff"Ta5d6ff📍Ta5d6ff"Tb4b4b4, Tb4b4b4(Tff7b72-T79c0ff1Tb4b4b4)Tb4b4b4.Te6edf3toCodePointStringTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertEqualsTb4b4b4(Ta5d6ff"Ta5d6ff📍Ta5d6ff"Tb4b4b4, T79c0ff0Te6edf3x110000Tb4b4b4.Te6edf3toCodePointStringTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertEqualsTb4b4b4(Ta5d6ff"Ta5d6ff📍Ta5d6ff"Tb4b4b4, T79c0ff0Te6edf3xFFFFFFFFTb4b4b4.Te6edf3toIntTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3toCodePointStringTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertEqualsTb4b4b4(Ta5d6ff"Ta5d6ff📍Ta5d6ff"Tb4b4b4, T79c0ff0Te6edf3xD800Tb4b4b4.Te6edf3toCodePointStringTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`zero renders as a control character without the waypoint helper`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// The premise for waypointIconOrDefault existing: zero is a valid scalar value, so toCodePointString has no
T8b949e// reason to substitute anything. If this ever starts returning the pushpin, the helper is redundant.
Te6edf3assertEqualsTb4b4b4(Ta5d6ff"Ta5d6ff\Ta5d6ffu0000Ta5d6ff"Tb4b4b4, T79c0ff0.Te6edf3toCodePointStringTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`waypointIconOrDefault maps the unset icon to the pushpin`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3assertEqualsTb4b4b4(Te6edf3PUSHPIN_CODE_POINTTb4b4b4, T79c0ff0.Te6edf3waypointIconOrDefaultTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertEqualsTb4b4b4(Ta5d6ff"Ta5d6ff📍Ta5d6ff"Tb4b4b4, T79c0ff0.Te6edf3waypointIconOrDefaultTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3toCodePointStringTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`waypointIconOrDefault leaves a chosen icon alone`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// Includes an out-of-range value: the helper resolves "unset", it is not a validity clamp — that is
T8b949e// toCodePointString's job, and conflating the two would silently discard the distinction.
Te6edf3assertEqualsTb4b4b4(Ta5d6ff'A'Tb4b4b4.Te6edf3codeTb4b4b4, Ta5d6ff'A'Tb4b4b4.Te6edf3codeTb4b4b4.Te6edf3waypointIconOrDefaultTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertEqualsTb4b4b4(T79c0ff0Te6edf3x1F600Tb4b4b4, T79c0ff0Te6edf3x1F600Tb4b4b4.Te6edf3waypointIconOrDefaultTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertEqualsTb4b4b4(Tff7b72-T79c0ff1Tb4b4b4, Tb4b4b4(Tff7b72-T79c0ff1Tb4b4b4)Tb4b4b4.Te6edf3waypointIconOrDefaultTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`toCodePointString honours an explicit fallback`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3assertEqualsTb4b4b4(Ta5d6ff"Ta5d6ff?Ta5d6ff"Tb4b4b4, Tb4b4b4(Tff7b72-T79c0ff1Tb4b4b4)Tb4b4b4.Te6edf3toCodePointStringTb4b4b4(Te6edf3fallback Tff7b72= Ta5d6ff'?'Tb4b4b4.Te6edf3codeTb4b4b4)Tb4b4b4)
T8b949e// A bogus fallback must not propagate the throw either.
Te6edf3assertEqualsTb4b4b4(Ta5d6ff"Ta5d6ff📍Ta5d6ff"Tb4b4b4, Tb4b4b4(Tff7b72-T79c0ff1Tb4b4b4)Tb4b4b4.Te6edf3toCodePointStringTb4b4b4(Te6edf3fallback Tff7b72= Tff7b72-T79c0ff2Tb4b4b4)Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.05s